package com.meiyou.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.meiyou.mapper.MeiyouZfbMapper;
import com.meiyou.pojo.MeiyouZfb;
import com.meiyou.pojo.MeiyouZfbExample;
import com.meiyou.service.ZfbService;
import com.meiyou.utils.Msg;
@Service
public class ZfbServiceImpl implements ZfbService{
    @Resource
    private MeiyouZfbMapper meiyouZfbMapper;
	
	public int insZfb(MeiyouZfb meiyouZfb) {
		int index = meiyouZfbMapper.insert(meiyouZfb);
		if(index>0){
			return 1;
		}
		return 0;
	}

	
	public List<MeiyouZfb> selZfb(String zUCount) {
		MeiyouZfbExample example=new MeiyouZfbExample();
		if(zUCount!=null){
		example.createCriteria().andZUCountEqualTo(zUCount);
		}
		return meiyouZfbMapper.selectByExample(example);
	}
 

	
	public Msg binZfb(MeiyouZfb meiyouZfb) {
		Msg msg;
		// TODO Auto-generated method stub
		MeiyouZfbExample example = new MeiyouZfbExample();
		MeiyouZfbExample.Criteria criteria = example.createCriteria();
		criteria.andZUCountEqualTo(meiyouZfb.getzUCount());
		List<MeiyouZfb> list = meiyouZfbMapper.selectByExample(example);
		if(list==null||list.size()==0) {
			int i = meiyouZfbMapper.insertSelective(meiyouZfb);
			if(i==1) {
				msg = Msg.success();
				return msg;
			}else {
				msg = Msg.fail();
				return msg;
			}
		}else {
			msg = Msg.fail();
			msg.setMsg("已绑定支付宝");
			return msg;
		}
	}


}
